#include <iostream>
#include "lmanagerdao_file_impl.h"
#include <unistd.h>
#include <stdio.h>

using namespace std;
using namespace MC;

vector<Lmanager*>& LmanagerDaoFileImpl::load(vector<Lmanager*>& managers)
{
	cout << endl;
	FILE* frp = fopen("managers.dat","r");
	if(frp == NULL)
	{
		return managers;
	}
	managers.clear();
	
	int ret =1; 
	while(ret)
	{	
		Lmanager* manager =new Lmanager;
		ret =fread(manager,sizeof(Lmanager),1,frp);
		if(ret)		
			managers.push_back(manager);
		
	}
	//delete [] anager;
	fclose(frp);
	return managers;
	
}
void LmanagerDaoFileImpl::save(vector<Lmanager*>& managers)
{
	FILE* fwp = fopen("managers.dat","wb");
	if(fwp == NULL)
	{
		perror("fopen");
		return;
	}
	
	for(unsigned int i=0; i<managers.size(); i++)
	{
		fwrite(managers.at(i),sizeof(Lmanager),1,fwp);
	}
	
	fclose(fwp);
}
